﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

namespace Hxsoft.AppV1.Admin.Controls
{
	public partial class OperationNavigation : BaseUserControl
	{
		#region property
		/// <summary>
		/// 导航项。
		/// </summary>
		public Dictionary<string, OperationNavigationItem> NavigationItems
		{
			get
			{
				if (ViewState["NavigationItems"] == null)
					ViewState["NavigationItems"] = new Dictionary<string, OperationNavigationItem>();
				return (Dictionary<string, OperationNavigationItem>)ViewState["NavigationItems"];
			}
		}

		/// <summary>
		/// 当前的导航项键值。
		/// </summary>
		public string CurrentKey
		{
			get { return (string)ViewState["CurrentKey"]; }
			set { ViewState["CurrentKey"] = value; }
		}
		#endregion

		protected void Page_Load(object sender, EventArgs e)
		{
			if (!IsPostBack)
			{
				RpNavigation.DataSource = NavigationItems;
				this.DataBind();
			}
		}

		#region Method
		/// <summary>
		/// 取得项的 HTML 代码。
		/// </summary>
		/// <param name="item">项。</param>
		/// <returns>项的 HTML 代码。</returns>
		public string GetItemHtml(KeyValuePair<string, OperationNavigationItem> item)
		{
			string frontHtml = "", backHtml = "";

			if (item.Key == CurrentKey)
			{
				frontHtml = @"<td class=""CurrentTabBox"">";
				backHtml = @"</td>";
			}
			else
			{
				frontHtml = @"<td class=""TabBox""><a href=""" + this.ResolveUrl(item.Value.NavigationUrl) + @""">";
				backHtml = @"</a></td>";
			}

			return frontHtml + item.Value.Text + backHtml;
		}
		#endregion
	}
}